
import Block from "./Block"
import GridSystem from "../GridSystem"
import { BlockCategory } from "../Constants";

class MyCircle extends Block {
    constructor(x: number, y: number, width: number, height: number, fill?: string) {
        super(x, y, width, height);
        this.category = BlockCategory.CIRCLE;
    }

    draw(x: number, y: number, width: number, height: number, angle?: number) {


        let ctx = GridSystem.gls.ctx;
        ctx.save()
        let { x: x1, y: y1 } = this.setAdsorption(x, y, width, height)
        x = x1;
        y = y1;

        this.setAngle(x, y, width, height)
        this.setSizeInfo(x, y, width, height)

        // ------ 公共部分
        ctx.beginPath()
        ctx.arc(x + width / 2, y + width / 2, width/2, 0, 2 * Math.PI);
        // var a = width
        // var r = 1/a; // ①注意：此处r可以写死，不过不同情况下写死的值不同
        // ctx.beginPath();
        // ctx.moveTo(x + a + width/2, y+width/2);
        // for(var i = 0; i < 2 * Math.PI; i += r) {
        //     ctx.lineTo(x + a * Math.cos(i), y + a * Math.sin(i));
        // }

        ctx.fillStyle = this.isTouch ? this.touchFill : this.fill;	//再填充
        ctx.fill();	//再填充
        ctx.restore()
        this.setFocusStyle();
        this.setControlPoints(x, y, width, height);
        this.isDraged = false;
        this.drawLink(x, y, width, height);
        this.update(x, y, width, height)
    }
}

export default MyCircle;